package org.zty.db;

import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.zty.db.POJOAttr.Type;
import org.zty.util.FileUtil;
import org.zty.util.ZException;

public class AdminLTETools {
	String basePath = "d:/adminLTECreateFile/";
	String controllerPath = basePath+"controller/";
	String servicePath = basePath+"service/";
	String webPath = basePath+"webapps/";
	
	/**
	 * 以下两个SB是给生成JS用的
	 */
	StringBuffer jsActionblock = new StringBuffer();
	StringBuffer jsBblock = new StringBuffer();
	FileUtil fu = new FileUtil();
	private List<POJOAttr> parseMySQLData(List<String[]> list){
		List<POJOAttr> pojoAttrList = new ArrayList<POJOAttr>();
		for(String[] item : list){
			POJOAttr p = new POJOAttr();
			p.setName(item[0]) ;
			Type type = null;
			if("bigint".equals(item[1].toLowerCase().trim())){
				type=Type.LONG;
			}else if("int".equals(item[1].toLowerCase().trim())){
				type=Type.INT;
			}else if(item[1].toLowerCase().indexOf("char")!=-1){
				type=Type.STRING;
			}else if(item[1].toLowerCase().indexOf("date")!=-1||item[1].toLowerCase().indexOf("time")!=-1){
				type=Type.DATE;
			}
			p.setType(type);
			p.setLength(Integer.parseInt(item[2]));
			pojoAttrList.add(p);
		}
		return pojoAttrList;
	}
	private void checkFilePath(){
		fu.mkdirs(webPath);
		fu.mkdirs(controllerPath);
		fu.mkdirs(servicePath);
	}
	public void createCurTable(String curTable,String driver,String url,String username,String password) throws SQLException{
		List<String[]> list = JDBC.getTableDesc(curTable, driver, url, username, password);
		checkFilePath();
		List<POJOAttr> pojoAttrList = parseMySQLData(list);
		
		createHtmlFile1(curTable,pojoAttrList);
		appendJsActionBlockStr(curTable, pojoAttrList);
		appendJsBBlockStr(curTable, pojoAttrList);
		createControllerJavaSrc(curTable, pojoAttrList);
		createServiceJavaSrc(curTable, pojoAttrList);
	}
	
	public String getFirstBigName(String name){
		 name = name.substring(0, 1).toUpperCase() + name.substring(1);
	     return  name;
	}
	
	/**
	 * 生成xxx.html
	 */
	private void createHtmlFile1(String curTable,List<POJOAttr> pojoAttrList){
		fu.mkdirs(webPath+curTable);
		String bcurTable = getFirstBigName(curTable);
		/**
		 * 下面会生成一个很长很长的文件
		 */
		StringBuffer sb= new StringBuffer();
		sb.append("<!DOCTYPE html>\r\n");
		sb.append("<html>\r\n");
		sb.append("<head>\r\n");
		sb.append("    <meta charset=\"utf-8\">\r\n");
		sb.append("    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\r\n");
		sb.append("    <title>"+bcurTable+"</title>\r\n");
		sb.append("    <!-- Tell the browser to be responsive to screen width -->\r\n");
		sb.append("    <meta content=\"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no\" name=\"viewport\">\r\n");
		sb.append("    <!-- Bootstrap 3.3.7 -->\r\n");
		sb.append("    <link rel=\"stylesheet\" href=\"/components/bootstrap/dist/css/bootstrap.min.css\">\r\n");
		sb.append("    <!-- Font Awesome 字体图标库-->\r\n");
		sb.append("    <link rel=\"stylesheet\" href=\"/components/font-awesome/css/font-awesome.min.css\">\r\n");
		sb.append("    <!-- Ionicons 字体图标库 -->\r\n");
		sb.append("    <link rel=\"stylesheet\" href=\"/components/Ionicons/css/ionicons.min.css\">\r\n");
		sb.append("    <!-- Theme style -->\r\n");
		sb.append("    <link rel=\"stylesheet\" href=\"/css/content.css\">\r\n");
		sb.append("    <link rel=\"stylesheet\" href=\"/css/eps-client.css\">\r\n");
		sb.append("    <!-- AdminLTE Skins. Choose a skin from the css/skins\r\n");
		sb.append("         folder instead of downloading all of them to reduce the load. -->\r\n");
		sb.append("    <link rel=\"stylesheet\" href=\"/css/skins/_all-skins.min.css\">\r\n");
		sb.append("    <!-- Morris chart 图标的 暂时不用-->\r\n");
		sb.append("    <!--<link rel=\"stylesheet\" href=\"/components/morris.js/morris.css\">-->\r\n");
		sb.append("    <!-- jvectormap 矢量地图 暂时不用-->\r\n");
		sb.append("    <!--<link rel=\"stylesheet\" href=\"/components/jvectormap/jquery-jvectormap.css\">-->\r\n");
		sb.append("    <!-- Date Picker -->\r\n");
		sb.append("    <link rel=\"stylesheet\" href=\"/components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css\">\r\n");
		sb.append("    <!-- Daterange picker -->\r\n");
		sb.append("    <link rel=\"stylesheet\" href=\"/components/bootstrap-daterangepicker/daterangepicker.css\">\r\n");
		sb.append("    <link rel=\"stylesheet\" href=\"/components/jquery-pagination/style/pagination.css\">\r\n");
		sb.append("    <!-- bootstrap wysihtml5 - text editor -->\r\n");
		sb.append("    <!--<link rel=\"stylesheet\" href=\"/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css\">-->\r\n");
		sb.append("\r\n");
		sb.append("    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->\r\n");
		sb.append("    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->\r\n");
		sb.append("    <!--[if lt IE 9]>\r\n");
		sb.append("    <!--<script src=\"https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js\"></script> IE8兼容性 用不到-->\r\n");
		sb.append("    <!--<script src=\"https://oss.maxcdn.com/respond/1.4.2/respond.min.js\"></script> IE8兼容性 用不到-->\r\n");
		sb.append("    <![endif]-->\r\n");
		sb.append("\r\n");
		sb.append("    <!-- Google Font -->\r\n");
		sb.append("    <link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic\">\r\n");
		sb.append("</head>\r\n");
		sb.append("<body class=\"hold-transition skin-blue iframe_content_body\" >\r\n");
		sb.append("<!-- Content Wrapper. Contains page content -->\r\n");
		sb.append("<div >\r\n");
		sb.append("    <!-- Content Header (Page header) -->\r\n");
		sb.append("    <section class=\"content-header\">\r\n");
		sb.append("        <h1>\r\n");
		sb.append("            "+bcurTable+"\r\n");
		sb.append("            <small>Control panel</small>\r\n");
		sb.append("        </h1>\r\n");
		sb.append("        <ol class=\"breadcrumb\">\r\n");
		sb.append("            <li><a href=\"/dashboard.html\"><i class=\"fa fa-dashboard\"></i> Home</a></li>\r\n");
		sb.append("            <li class=\"active\"><a href=\"#\" onclick=\"location.reload()\">"+bcurTable+"</a></li>\r\n");
		sb.append("        </ol>\r\n");
		sb.append("\r\n");
		sb.append("    </section>\r\n");
		sb.append("\r\n");
		sb.append("    <section class=\"content\">\r\n");
		sb.append("        <div class=\"row d_s inner_page list_block\">\r\n");
		sb.append("        	<!-- 提示框 -->\r\n");
		sb.append("        	<div id=\"tip_block\"></div>\r\n");
		sb.append("            <div class=\"col-xs-12\">\r\n");
		sb.append("                <div class=\"box\">\r\n");
		sb.append("                    <div class=\"box-header\">\r\n");
		sb.append("                        <h3 class=\"box-title\">"+bcurTable+" List</h3>\r\n");
		sb.append("                        <div class=\"btn btn-default fright\" onclick=\"b.add"+bcurTable+"('form2')\"><i class=\"fa fa-fw fa-plus-circle mr-10\"></i>新增</div>\r\n");
		sb.append("                    </div>\r\n");
		sb.append("                    <!-- /.box-header -->\r\n");
		sb.append("                    <div class=\"box-body\">\r\n");
		sb.append("                        <div id=\"example2_wrapper\" class=\"dataTables_wrapper form-inline dt-bootstrap\">\r\n");
		sb.append("                            <div class=\"row\">\r\n");
		sb.append("                                <div class=\"col-sm-12\">\r\n");
		sb.append("                                    <table id=\"datatable\" class=\"table table-bordered table-hover dataTable\" role=\"grid\" aria-describedby=\"example2_info\">\r\n");
		sb.append("                                    <thead>\r\n");
		sb.append("                                    <tr role=\"row\">\r\n");
		
		for(POJOAttr attr : pojoAttrList){
			sb.append("                                        <th class=\"sorting\" tabindex=\"0\" aria-controls=\"example2\" rowspan=\"1\" colspan=\"1\" aria-label=\"Rendering engine: activate to sort column ascending\">"+attr.getFirstBigName()+"</th>\r\n");	
		}
		sb.append("											<th class=\"sorting\">Control</th>\r\n</tr>\r\n");
		sb.append("                                    </thead>\r\n");
		sb.append("                                    <tbody>\r\n");
		sb.append("\r\n");
		sb.append("                                    </tbody>\r\n");
		sb.append("                                    </table>\r\n");
		sb.append("                                    <div id=\"page_bar\"></div>\r\n");
		sb.append("                                </div>\r\n");
		sb.append("                            </div>\r\n");
		sb.append("                        </div>\r\n");
		sb.append("                    </div>\r\n");
		sb.append("                    <!-- /.box-body -->\r\n");
		sb.append("                </div>\r\n");
		sb.append("                <!-- /.box -->\r\n");
		sb.append("            </div>\r\n");
		sb.append("            <!-- /.col -->\r\n");
		sb.append("        </div>\r\n");
		sb.append("        <!-- /.row -->\r\n");
		sb.append("\r\n");
		sb.append("        <div class=\"row d_n inner_page update_form_block\">\r\n");
		sb.append("            <div class=\"col-md-6\">\r\n");
		sb.append("                <!-- general form elements -->\r\n");
		sb.append("                <div class=\"box box-primary\">\r\n");
		sb.append("                    <div class=\"box-header with-border\">\r\n");
		sb.append("                        <h3 class=\"box-title\">Form</h3>\r\n");
		sb.append("                    </div>\r\n");
		sb.append("                    <!-- /.box-header -->\r\n");
		sb.append("                    <!-- form start -->\r\n");
		sb.append("                    <form role=\"form\" id=\"form1\" name=\"form1\">\r\n");
		sb.append("                        <div class=\"box-body\">\r\n");
		
		for(POJOAttr attr:pojoAttrList){
			sb.append("                            <div class=\"form-group\">\r\n");
			sb.append("                                <label for=\""+attr.getName()+"\">"+attr.getFirstBigName()+"</label>\r\n");
			sb.append("                                <input type=\"text\" class=\"form-control\" id=\""+attr.getName()+"\" name=\""+attr.getName()+"\" placeholder=\""+attr.getFirstBigName()+"\">\r\n");
			sb.append("                            </div>\r\n");
		}
		sb.append("                        </div>\r\n");
		sb.append("\r\n");
		sb.append("                        <!-- /.box-body -->\r\n");
		sb.append("                        <div class=\"box-footer\">\r\n");
		sb.append("                            <button type=\"button\" class=\"btn btn-primary\" onclick=\"b.submit"+bcurTable+"('form1')\">Submit</button>\r\n");
		sb.append("                        </div>\r\n");
		sb.append("                    </form>\r\n");
		sb.append("                </div>\r\n");
		sb.append("                <!-- /.box -->\r\n");
		sb.append("            </div>\r\n");
		sb.append("        </div>\r\n");
		
		sb.append("        <div class=\"row d_n inner_page add_form_block\">\r\n");
		sb.append("            <div class=\"col-md-6\">\r\n");
		sb.append("                <!-- general form elements -->\r\n");
		sb.append("                <div class=\"box box-primary\">\r\n");
		sb.append("                    <div class=\"box-header with-border\">\r\n");
		sb.append("                        <h3 class=\"box-title\">Form</h3>\r\n");
		sb.append("                    </div>\r\n");
		sb.append("                    <!-- /.box-header -->\r\n");
		sb.append("                    <!-- form start -->\r\n");
		sb.append("                    <form role=\"form\" id=\"form2\" name=\"form2\">\r\n");
		sb.append("                        <div class=\"box-body\">\r\n");
		
		for(POJOAttr attr:pojoAttrList){
			sb.append("                            <div class=\"form-group\">\r\n");
			sb.append("                                <label for=\""+attr.getName()+"\">"+attr.getFirstBigName()+"</label>\r\n");
			sb.append("                                <input type=\"text\" class=\"form-control\" id=\""+attr.getName()+"\" name=\""+attr.getName()+"\" placeholder=\""+attr.getFirstBigName()+"\">\r\n");
			sb.append("                            </div>\r\n");
		}
		sb.append("                        </div>\r\n");
		sb.append("\r\n");
		sb.append("                        <!-- /.box-body -->\r\n");
		sb.append("                        <div class=\"box-footer\">\r\n");
		sb.append("                            <button type=\"button\" class=\"btn btn-primary\" onclick=\"b.submit"+bcurTable+"('form2')\">Submit</button>\r\n");
		sb.append("                        </div>\r\n");
		sb.append("                    </form>\r\n");
		sb.append("                </div>\r\n");
		sb.append("                <!-- /.box -->\r\n");
		sb.append("            </div>\r\n");
		sb.append("        </div>\r\n");
		
		
		sb.append("        <div class=\"row d_n inner_page view_block\">\r\n");
		sb.append("            <div class=\"col-md-6\">\r\n");
		sb.append("                <!-- general form elements -->\r\n");
		sb.append("                <div class=\"box box-primary\">\r\n");
		sb.append("                    <div class=\"box-header with-border\">\r\n");
		sb.append("                        <h3 class=\"box-title\">Form</h3>\r\n");
		sb.append("                    </div>\r\n");
		sb.append("                    <!-- /.box-header -->\r\n");
		sb.append("                    <!-- form start -->\r\n");
		sb.append("                    <form role=\"form\" id=\"form3\" name=\"form3\">\r\n");
		sb.append("                        <div class=\"box-body\">\r\n");
		
		for(POJOAttr attr:pojoAttrList){
			sb.append("                            <div class=\"form-group\">\r\n");
			sb.append("                                <label for=\""+attr.getName()+"\">"+attr.getFirstBigName()+"</label>\r\n");
			sb.append("                                <input disabled type=\"text\" class=\"form-control\" id=\""+attr.getName()+"\" name=\""+attr.getName()+"\" placeholder=\""+attr.getFirstBigName()+"\">\r\n");
			sb.append("                            </div>\r\n");
		}
		sb.append("                        </div>\r\n");
		sb.append("\r\n");
		sb.append("                        <!-- /.box-body -->\r\n");
		sb.append("                        <div class=\"box-footer\">\r\n");
		sb.append("                        </div>\r\n");
		sb.append("                    </form>\r\n");
		sb.append("                </div>\r\n");
		sb.append("                <!-- /.box -->\r\n");
		sb.append("            </div>\r\n");
		sb.append("        </div>\r\n");
		
		
		
		sb.append("\r\n");
		sb.append("    </section>\r\n");
		sb.append("    <!-- /.content -->\r\n");
		sb.append("</div>\r\n");
		sb.append("<!-- ./wrapper -->\r\n");
		sb.append("<!-- jQuery 3 -->\r\n");
		sb.append("<script src=\"/components/jquery/dist/jquery.min.js\"></script>\r\n");
		sb.append("<script src=\"/js/jquery.i18n.properties-1.0.9.js\"></script>");
		sb.append("<!-- jQuery UI 1.11.4 -->\r\n");
		sb.append("<script src=\"/components/jquery-ui/jquery-ui.min.js\"></script>\r\n");
		sb.append("<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->\r\n");
		sb.append("<script>\r\n");
		sb.append("    $.widget.bridge('uibutton', $.ui.button);\r\n");
		sb.append("</script>\r\n");
		sb.append("<!-- Bootstrap 3.3.7 -->\r\n");
		sb.append("<script src=\"/components/bootstrap/dist/js/bootstrap.min.js\"></script>\r\n");
		sb.append("<!-- Morris.js charts 图表,折线图 用到再说-->\r\n");
		sb.append("<!--<script src=\"/components/raphael/raphael.min.js\"></script>\r\n");
		sb.append("<script src=\"/components/morris.js/morris.min.js\"></script>-->\r\n");
		sb.append("<!-- Sparkline 图表,折线图 用到再说-->\r\n");
		sb.append("<!--<script src=\"/components/jquery-sparkline/dist/jquery.sparkline.min.js\"></script>-->\r\n");
		sb.append("<!-- jvectormap 矢量地图 用到再说-->\r\n");
		sb.append("<!--<script src=\"plugins/jvectormap/jquery-jvectormap-1.2.2.min.js\"></script>\r\n");
		sb.append("<script src=\"plugins/jvectormap/jquery-jvectormap-world-mill-en.js\"></script>-->\r\n");
		sb.append("<!-- jQuery Knob Chart 旋转按钮 图标 用到再说-->\r\n");
		sb.append("<!--<script src=\"/components/jquery-knob/dist/jquery.knob.min.js\"></script>-->\r\n");
		sb.append("<!-- daterangepicker 日期选择-->\r\n");
		sb.append("<script src=\"/components/moment/min/moment.min.js\"></script>\r\n");
		sb.append("<script src=\"/components/bootstrap-daterangepicker/daterangepicker.js\"></script>\r\n");
		sb.append("<!-- datepicker -->\r\n");
		sb.append("<script src=\"/components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js\"></script>\r\n");
		sb.append("<!-- Bootstrap WYSIHTML5 富文本客户端 用到再说-->\r\n");
		sb.append("<!--<script src=\"/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js\"></script>-->\r\n");
		sb.append("<!-- Slimscroll 滚动条插件-->\r\n");
		sb.append("<script src=\"/components/jquery-slimscroll/jquery.slimscroll.min.js\"></script>\r\n");
		sb.append("<script src=\"/components/jquery-pagination/js/jquery.pagination.min.js\"></script>\r\n");
		sb.append("<script src=\"/js/eps-client-tools.js\"></script>\r\n");
		sb.append("<script src=\"/js/eps-client-business.js\"></script>\r\n");
		sb.append("<!-- FastClick 移动端对click事件的处理 暂时用不到-->\r\n");
		sb.append("<!--<script src=\"/components/fastclick/lib/fastclick.js\"></script>-->\r\n");
		sb.append("<!-- AdminLTE App -->\r\n");
		sb.append("<!-- AdminLTE dashboard demo (This is only for demo purposes) -->\r\n");
		sb.append("<!-- AdminLTE for demo purposes -->\r\n");
		sb.append("<script>\r\n");
		sb.append("    $(document).ready(function(){\r\n");
		sb.append("        b.find"+bcurTable+"List();\r\n");
		sb.append("    });\r\n");
		sb.append("</script>\r\n");
		sb.append("</body>\r\n");
		sb.append("</html>\r\n");
		try {
			fu.crFile(sb.toString(), webPath+curTable+"/"+curTable+".html", "UTF-8");
		} catch (ZException e) {
			e.printStackTrace();
		}
	}
	
	private void appendJsActionBlockStr(String curTable,List<POJOAttr> pojoAttrList){
		String bcurTable = getFirstBigName(curTable);
		StringBuffer sb = new StringBuffer();
		sb.append("find"+bcurTable+"List:\"/"+curTable+"/list\",\r\n");
		sb.append("get"+bcurTable+":\"/"+curTable+"/get/\",\r\n");
		sb.append("update"+bcurTable+":\"/"+curTable+"/update\",\r\n");
		sb.append("add"+bcurTable+":\"/"+curTable+"/add\",\r\n");
		sb.append("delete"+bcurTable+":\"/"+curTable+"/delete/\",\r\n");
		jsActionblock.append(sb);
	}
	
	private void appendJsBBlockStr(String curTable,List<POJOAttr> pojoAttrList){
		
		String bcurTable = getFirstBigName(curTable);
		StringBuffer sb = new StringBuffer();
		sb.append("find"+bcurTable+"List:function(pageNumber,pageSize){\r\n");
		sb.append("    switchPage(\"list_block\");\r\n");
		sb.append("    showList(pageNumber,pageSize,action.find"+bcurTable+"List,function(item){\r\n");
		sb.append("        return \"<tr>");
		for(POJOAttr attr :pojoAttrList){
			sb.append("<td>\"+item."+attr.getName()+"+\"</td>");
		}
		
		sb.append("<td>"
				+ "<button type='button' class='btn btn-primary' onclick='b.update"+bcurTable+"(\\\"form1\\\",\"+item.id+\")'>修改</button>"
				+ "<button type='button' class='btn btn-danger ml-10' onclick='parent.cfm(\\\"确认删除?\\\",function(){b.delete"+bcurTable+"(\"+item.id+\")},\\\"danger\\\")'>删除</button>"
				+ "<button type='button' class='btn btn-success ml-10' onclick='b.get"+bcurTable+"(\\\"form3\\\",\"+item.id+\")'>查看</button>"
				+ "</td></tr>\";\r\n");
		sb.append("    },b.find"+bcurTable+"List);\r\n");
		sb.append("},\r\n");
		sb.append("get"+bcurTable+":function(formId,id){\r\n");
		sb.append("    switchPage(\"view_block\");\r\n");
		sb.append("    $(\"#\"+formId)[0].reset();\r\n");
		sb.append("    if(id==null){\r\n");
		sb.append("        return;\r\n");
		sb.append("    }\r\n");
		sb.append("    postData(action.get"+bcurTable+"+id,null,function(data){\r\n");
		sb.append("        $(\"#\"+formId).populateForm(data);\r\n");
		sb.append("    })\r\n");
		sb.append("},\r\n");
		sb.append("update"+bcurTable+":function(formId,id){\r\n");
		sb.append("    switchPage(\"update_form_block\");\r\n");
		sb.append("    $(\"#\"+formId)[0].reset();\r\n");
		sb.append("    if(id==null){\r\n");
		sb.append("        return;\r\n");
		sb.append("    }\r\n");
		sb.append("    postData(action.get"+bcurTable+"+id,null,function(data){\r\n");
		sb.append("        $(\"#\"+formId).populateForm(data);\r\n");
		sb.append("    })\r\n");
		sb.append("},\r\n");
		sb.append("add"+bcurTable+":function(formId,id){\r\n");
		sb.append("    switchPage(\"add_form_block\");\r\n");
		sb.append("    $(\"#\"+formId)[0].reset();\r\n");
		sb.append("},\r\n");
		sb.append("submit"+bcurTable+":function(formId){\r\n");
		sb.append("    switchPage(\"form_block\");\r\n");
		sb.append("    if($(\"#\"+formId+\" input[name=id]\").val().trim().length==0){\r\n");
		sb.append("        //代表是新增\r\n");
		sb.append("        postData(action.add"+bcurTable+",getFormData(formId),function(data){\r\n");
		sb.append("            $(\"#\"+formId)[0].reset();\r\n");
		sb.append("            b.find"+bcurTable+"List(defaultPageNumber,defaultPageSize);\r\n");
		sb.append("        });\r\n");
		sb.append("    }else{\r\n");
		sb.append("        postData(action.update"+bcurTable+",getFormData(formId),function(data){\r\n");
		sb.append("            $(\"#\"+formId)[0].reset();\r\n");
		sb.append("            b.find"+bcurTable+"List(defaultPageNumber,defaultPageSize);\r\n");
		sb.append("        });\r\n");
		sb.append("    }\r\n");
		sb.append("},\r\n");
		sb.append("delete"+bcurTable+":function(id){\r\n");
		sb.append("    postData(action.delete"+bcurTable+"+id,null,function(data){\r\n");
		sb.append("        b.find"+bcurTable+"List(defaultPageNumber,defaultPageSize);\r\n");
		sb.append("    });\r\n");
		sb.append("},\r\n");
		jsBblock.append(sb);
	}
	
	public void createJSfile(){
		fu.mkdirs(webPath+"js/");
		StringBuffer jsStr = new StringBuffer();
		jsStr.append("var action = {\r\n");
		/**
		 * 下面这句话就是为了去掉最后一个, T.T
		 */
		jsStr.append(jsActionblock.substring(0,jsActionblock.toString().lastIndexOf(","))+jsActionblock.substring(jsActionblock.toString().lastIndexOf(",")+1));
		
		jsStr.append("}\r\n");
		
		jsStr.append("var b ={\r\n");
		jsStr.append(jsBblock.substring(0,jsBblock.toString().lastIndexOf(","))+jsBblock.substring(jsBblock.toString().lastIndexOf(",")+1));
		jsStr.append("}\r\n");
		try {
			fu.crFile(jsStr.toString(), webPath+"js/eps-client-business.js", "UTF-8");
		} catch (ZException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void createControllerJavaSrc(String curTable,List<POJOAttr> pojoAttrList){
		String bcurTable = getFirstBigName(curTable);
		StringBuffer sb = new StringBuffer();
		sb.append("package com.gd.controller;\r\n");
		sb.append("import java.util.Date;\r\n");
		sb.append("\r\n");
		sb.append("import com.gd.common.model."+bcurTable+";\r\n");
		sb.append("import com.gd.service."+bcurTable+"Service;\r\n");
		sb.append("import com.gd.common.I18nTag;\r\n");
		sb.append("import com.jfinal.json.FastJson;\r\n");
		sb.append("import com.jfinal.kit.HttpKit;\r\n");
		sb.append("import com.jfinal.plugin.activerecord.Page;\r\n");
		sb.append("import net.sf.json.JSONObject;\r\n");
		sb.append("\r\n");
		sb.append("public class "+bcurTable+"Controller extends BaseController{\r\n");
		sb.append("	static "+bcurTable+"Service "+curTable+"Service = new "+bcurTable+"Service();\r\n");
		sb.append("	public void update(){\r\n");
		sb.append("		"+bcurTable+" "+curTable+" = FastJson.getJson().parse(JsonParam.toString(), "+bcurTable+".class);\r\n");
		sb.append("		if("+curTable+".getId()==null){\r\n");
		sb.append("			err();\r\n");
		sb.append("			return;\r\n");
		sb.append("		}\r\n");
		sb.append("		"+curTable+".update();\r\n");
		sb.append("		suc(getI18n(I18nTag.SUCCESS));\r\n");
		sb.append("	}\r\n");
		sb.append("	\r\n");
		sb.append("	public void add(){\r\n");
		sb.append("		"+bcurTable+" "+curTable+" = FastJson.getJson().parse(JsonParam.toString(), "+bcurTable+".class);\r\n");
		sb.append("		"+curTable+"Service.save("+curTable+");\r\n");
		sb.append("		suc(getI18n(I18nTag.SUCCESS));\r\n");
		sb.append("	}\r\n");
		sb.append("	\r\n");
		sb.append("	public void delete(){\r\n");
		sb.append("		int id = getParaToInt();\r\n");
		sb.append("		"+curTable+"Service.deleteById(id);\r\n");
		sb.append("		suc(getI18n(I18nTag.SUCCESS));\r\n");
		sb.append("	}\r\n");
		sb.append("	\r\n");
		sb.append("	public void get() {\r\n");
		sb.append("		int id = getParaToInt();\r\n");
		sb.append("		"+bcurTable+" "+curTable+" = "+curTable+"Service.findById(id);\r\n");
		sb.append("		JSONObject json = putData(FastJson.getJson().toJson("+curTable+"));\r\n");
		sb.append("		suc(json);\r\n");
		sb.append("	}\r\n");
		sb.append("	public void list(){\r\n");
		sb.append("		Page<"+bcurTable+"> "+curTable+" = "+curTable+"Service.paginate(getPageParam());\r\n");
		sb.append("		String data = FastJson.getJson().toJson("+curTable+");\r\n");
		sb.append("		JSONObject json = putData(data);\r\n");
		sb.append("		suc(json);\r\n");
		sb.append("	}\r\n");
		sb.append("}\r\n");
		
		try {
			fu.crFile(sb.toString(),controllerPath+bcurTable+"Controller.java","UTF-8");
		} catch (ZException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public void createServiceJavaSrc(String curTable,List<POJOAttr> pojoAttrList){
		String bcurTable = getFirstBigName(curTable);
		StringBuffer sb = new StringBuffer();
		sb.append("package com.gd.service;\r\n");
		sb.append("import java.util.Date;\r\n");
		sb.append("import com.gd.common.model."+bcurTable+";\r\n");
		sb.append("import com.gd.util.RequestPage;\r\n");
		sb.append("import com.jfinal.plugin.activerecord.Page;\r\n");
		sb.append("\r\n");
		sb.append("public class "+bcurTable+"Service {\r\n");
		sb.append("	/**\r\n");
		sb.append("	 * 所有的 dao 对象也放在 Service 中\r\n");
		sb.append("	 */\r\n");
		sb.append("	private static final "+bcurTable+" dao = new "+bcurTable+"().dao();\r\n");
		sb.append("\r\n");
		sb.append("\r\n");
		sb.append("	public Page<"+bcurTable+"> paginate(RequestPage rp) {\r\n");
		sb.append("		return dao.paginate(rp.pageNumber, rp.pageSize, \"select * \", \"from "+curTable+" order by id asc\");\r\n");
		sb.append("	}\r\n");
		sb.append("\r\n");
		sb.append("	public "+bcurTable+" save("+bcurTable+" "+curTable+"){\r\n");
		sb.append("		"+curTable+".setCreateTime(new Date());\r\n");
		sb.append("		"+curTable+".save();\r\n");
		sb.append("		return "+curTable+";\r\n");
		sb.append("	}\r\n");
		sb.append("\r\n");
		sb.append("	public "+bcurTable+" update("+bcurTable+" "+curTable+"){\r\n");
		sb.append("		"+curTable+".update();\r\n");
		sb.append("		return "+curTable+";\r\n");
		sb.append("	}\r\n");
		sb.append("\r\n");
		sb.append("	public "+bcurTable+" findById(int id) {\r\n");
		sb.append("		return dao.findById(id);\r\n");
		sb.append("	}\r\n");
		sb.append("\r\n");
		sb.append("	public void deleteById(int id) {\r\n");
		sb.append("		dao.deleteById(id);\r\n");
		sb.append("	}\r\n");
		sb.append("\r\n");
		sb.append("}\r\n");
		try {
			fu.crFile(sb.toString(),servicePath+bcurTable+"Service.java","UTF-8");
		} catch (ZException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
